package com.infore.airsupervise.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.beardedhen.androidbootstrap.AwesomeTextView;
import com.infore.airsupervise.R;
import com.infore.airsupervise.bean.AwesomeIconItem;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 主抽屉视图列表适配器
 *
 * @features: feature
 * @author: Ding Xinlin
 * @date: 2017/03/03 17:44
 */

public class MainDrawerListAdapter extends BaseAdapter {

    private List<AwesomeIconItem> datas;
    private LayoutInflater layoutInflater;

    public MainDrawerListAdapter(Context context, List<AwesomeIconItem> datas) {
        this.layoutInflater = LayoutInflater.from(context);
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas==null ? 0 : datas.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = layoutInflater.inflate(R.layout.item_main_drawer_list, viewGroup, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        AwesomeIconItem data = datas.get(i);
        holder.icon.setImageResource(data.getResId());
        holder.title.setText(data.getText());

        return view;
    }

    class ViewHolder {
        @BindView(R.id.menu_icon)
        ImageView icon;
        @BindView(R.id.menu_title)
        TextView title;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
